package previous.Test_0323;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
public class Bridge_Blue {
    //寻找2022
    public static void main1(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int[][] num=new int[300][300];
        for (int i = 0; i < 300; i++) {
            String s=scan.nextLine();
            for (int j = 0; j < 300; j++) {
             num[i][j]=s.charAt(j)-'0';
            }
        }
        //每一行
        int count=0;
        for (int i = 0; i < 300; i++) {
            for (int j = 0; j < 300-3; j++) {
                if(num[i][j]==2 &&
                 num[i][j+1]==0 &&
                 num[i][j+2]==2 &&
                 num[i][j+3]==0
                ){
                    count++;
                }
            }
        }
        //每一列
        for (int i = 0; i <300-3 ; i++) {
            for (int j = 0; j < 300; j++) {
                if(num[i][j]==2 &&
                        num[i+1][j]==0 &&
                        num[i+2][j]==2 &&
                        num[i+3][j]==0
                ){
                    count++;
                }
            }
        }
        //对角线
        for (int i = 0; i <300-3 ; i++) {
            for (int j = 0; j < 300-3; j++) {
                if(num[i][j]==2 &&
                        num[i+1][j+1]==0 &&
                        num[i+2][j+2]==2 &&
                        num[i+3][j+3]==0
                ){
                    count++;
                }
            }
        }
        System.out.println(count);
        scan.close();
    }
    public static void main4(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int[] a = {5, 12, 35, 28, 19, 22, 36, 17, 4, 11};
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i]+" ");
        }
        Arrays.sort(a);
        System.out.println();
        for (int i = 0; i < a.length; i++) {
             System.out.print(a[i]+" ");
        }
        scan.close();
    }
    //数字三角形
    public static void main5(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n=scan.nextInt();
        int[][] num=new int[n][n];
        int[][] dp=new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <=i ; j++) {
                num[i][j]=scan.nextInt();
            }
        }
        dp[0][0]=num[0][0];
        for (int i = 1; i <n ; i++) {
            for (int j = 0; j <=i; j++) {
               //分情况讨论
                //如果是第0列
                if(j==0){
                    dp[i][j]=dp[i-1][j]+num[i][j];
                    //最后一列
                }else if(j==i){
                    dp[i][j]=dp[i-1][j-1]+num[i][j];
                    //中间元素
                }else{
                    dp[i][j]=Math.max(dp[i-1][j],dp[i-1][j-1])+num[i][j];
                }
            }
        }
       int max=0;
        for (int i = 0; i <n ; i++) {
            int left=i;
            int right=n-1-left;
            if(Math.abs(left-right)<=1){
                max=Math.max(max,dp[n-1][i]);
            }
        }
        System.out.println(max);
        scan.close();
    }
    public static void main6(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        char c='L';
        System.out.println((int)c);
        scan.close();
    }
    public static void main7(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n=scan.nextInt();
        for (int i = 1; i <n ; i++) {
            if(i*i>=n){
                System.out.println(i);
                return;
            }
        }
        scan.close();
    }
    //杨辉三角
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n=scan.nextInt();
        int[][] num=new int[n][n];
        if(n==1){
            System.out.println(1);
            return;
        }
        //第一列和最后一列为1
        for (int i = 0; i < n; i++) {
            num[i][0]=1;
            num[i][i]=1;
        }
       //中间
        for (int i = 2; i <n; i++) {
            for (int j = 1; j <i ; j++) {
                num[i][j]=num[i-1][j]+num[i-1][j-1];
            }
        }
        long count=0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <i ; j++) {
                count++;
                if(num[i][j]==n){
                    System.out.println(count);
                    return;
                }
            }
        }
        scan.close();
    }
    //卡片
    public static void main10(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n=scan.nextInt();
        for (int i = 1; i <n ; i++) {
            if(n<=i*(i+1)/2){
                System.out.println(i);
                return;
            }
        }
        scan.close();
    }
    //直线
    public static void main12(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        Set<double[]> set=new HashSet<>();
        double k=0,b=0;
        for (int x1 = 0; x1 < 21; x1++) {
            for (int y1 = 0; y1 < 21; y1++) {
                for (int x2 = 0; x2 < 21; x2++) {
                    for (int y2 = 0; y2 < 21; y2++) {
                        if(x1!=x2){
                            k=((double)(y2-y1)/(x2-x1));
                            b=y1-k*x1;
                        }else if(x1==x2 && y1!=y2){
                           continue;
                        }else{
                            k=Double.MAX_VALUE;
                            b=x1;
                        }
                        set.add(new double[]{k,b});
                    }
                }
            }
        }
        System.out.println(set.size());
        scan.close();
    }

        public static void main13(String[] args) {
            Set<double[]> set = new HashSet<>();
            double k = 0, b = 0;
            for (int x1 = 0; x1 < 20; x1++) {
                for (int y1 = 0; y1 < 21; y1++) {
                    for (int x2 = 0; x2 < 20; x2++) {
                        for (int y2 = 0; y2 < 21; y2++) {
                            if (x1 != x2) {
                                k = ((double) (y2 - y1)) / (x2 - x1);
                                b = y1 - k * x1;
                            } else if (x1 == x2 && y1 != y2) {
                                k = Double.MAX_VALUE;
                                b = x1;
                            } else {
                                continue;
                            }
                            set.add(new double[]{k, b});
                        }
                    }
                }
            }
            System.out.println(set.size());
        }
}


